﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace iTeamyou.LTS.Core.Migrations
{
    public partial class Update1002 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropPrimaryKey(
                name: "PK_ProductLicenseAttachments",
                table: "ProductLicenseAttachments");

            migrationBuilder.RenameColumn(
                name: "ValidDate",
                table: "ProductLicenses",
                newName: "ValidToDate");

            migrationBuilder.RenameColumn(
                name: "Tag",
                table: "ProductLicenses",
                newName: "Type");

            migrationBuilder.RenameColumn(
                name: "SKU",
                table: "ProductLicenses",
                newName: "LId");

            migrationBuilder.AlterColumn<int>(
                name: "Category",
                table: "Products",
                type: "int",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "longtext")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "SupplierId",
                table: "Products",
                type: "longtext",
                nullable: false)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<string>(
                name: "ProductId",
                table: "ProductLicenses",
                type: "varchar(95)",
                nullable: false,
                defaultValue: "")
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<DateTime>(
                name: "ValidFromDate",
                table: "ProductLicenses",
                type: "datetime",
                nullable: true);

            migrationBuilder.AddPrimaryKey(
                name: "PK_ProductLicenseAttachments",
                table: "ProductLicenseAttachments",
                columns: new[] { "Id", "LicenseId" });

            migrationBuilder.CreateIndex(
                name: "IX_ProductLicenses_ProductId",
                table: "ProductLicenses",
                column: "ProductId");

            migrationBuilder.AddForeignKey(
                name: "FK_ProductLicenses_Products_ProductId",
                table: "ProductLicenses",
                column: "ProductId",
                principalTable: "Products",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_ProductLicenses_Products_ProductId",
                table: "ProductLicenses");

            migrationBuilder.DropIndex(
                name: "IX_ProductLicenses_ProductId",
                table: "ProductLicenses");

            migrationBuilder.DropPrimaryKey(
                name: "PK_ProductLicenseAttachments",
                table: "ProductLicenseAttachments");

            migrationBuilder.DropColumn(
                name: "SupplierId",
                table: "Products");

            migrationBuilder.DropColumn(
                name: "ProductId",
                table: "ProductLicenses");

            migrationBuilder.DropColumn(
                name: "ValidFromDate",
                table: "ProductLicenses");

            migrationBuilder.RenameColumn(
                name: "ValidToDate",
                table: "ProductLicenses",
                newName: "ValidDate");

            migrationBuilder.RenameColumn(
                name: "Type",
                table: "ProductLicenses",
                newName: "Tag");

            migrationBuilder.RenameColumn(
                name: "LId",
                table: "ProductLicenses",
                newName: "SKU");

            migrationBuilder.UpdateData(
                table: "Products",
                keyColumn: "Category",
                keyValue: null,
                column: "Category",
                value: "");

            migrationBuilder.AlterColumn<string>(
                name: "Category",
                table: "Products",
                type: "longtext",
                nullable: false,
                oldClrType: typeof(int),
                oldType: "int",
                oldNullable: true)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddPrimaryKey(
                name: "PK_ProductLicenseAttachments",
                table: "ProductLicenseAttachments",
                column: "Id");
        }
    }
}
